package com.xk857.simpleeffect.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import com.facebook.shimmer.ShimmerFrameLayout;
import com.xk857.simpleeffect.AppNoticeActivity;
import com.xk857.simpleeffect.R;
import com.xk857.simpleeffect.db.PersonDataBase;
import com.xuexiang.xui.widget.actionbar.TitleBar;
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog;

public class AboutActivity extends AppCompatActivity {

    private ShimmerFrameLayout shimmerViewContainer;
    private LinearLayout userLayout;
    private LinearLayout privateLayout;
    private LinearLayout deleteLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.white));
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        setContentView(R.layout.activity_about);
        initView();
    }

    private void initView() {
        TitleBar titleBar = findViewById(R.id.title_bar);
        titleBar.setLeftClickListener(v -> finish());
        shimmerViewContainer = findViewById(R.id.shimmer_view_container);
        userLayout = findViewById(R.id.user_layout);
        privateLayout = findViewById(R.id.private_layout);
        deleteLayout = findViewById(R.id.delete_layout);

        userLayout.setOnClickListener(v -> {
            Intent intent = new Intent(this, AppNoticeActivity.class);
            intent.putExtra("isPrivate", false);
            startActivity(intent);
        });

        privateLayout.setOnClickListener(v -> {
            Intent intent = new Intent(this, AppNoticeActivity.class);
            intent.putExtra("isPrivate", true);
            startActivity(intent);
        });

        deleteLayout.setOnClickListener(v -> {
            new MaterialDialog.Builder(this).iconRes(R.drawable.icon_info).title(R.string.info).content("您确定要退出登录吗？")
                    .positiveText(R.string.yes).negativeText(R.string.cancel).onPositive((dialog, which) -> {
                        PersonDataBase.removePersonInfo(this);
                        this.startActivity(new Intent(this, LoginActivity.class));
                    }).show();
        });
    }
}